<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CopyImage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $source;
    protected $target;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($source, $target)
    {
        $this->source = $source;
        $this->target = $target;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if (is_file($this->source)) {
            if (!is_file($this->target)){
                echo '<p>++++++'.$this->target.'</p>';
                @mkdir(dirname($this->target), 0777, true);
                copy($this->source, $this->target);
            }
        }else{
            echo '<p>------'.$this->source.'</p>';
        }
    }
}
